/*
* @Author: z.p
* @Project: Zdotp
* @Date: 2025年01月18日
* @Description: 网关handler
*/
using Pb;
using Zdotp.Actor;
using Zdotp.Actor.Controller;
using Zdotp.Actor.Kcp;
using Zdotp.Actor.Packet;
using Zdotp.Net.NetMessageHandler;

namespace MultiGateServer.Actors;

public class KcpHandler : KcpMessageHandler<DataPacket>
{
    protected override void Run(ActorKcp kcpActor, ActorSystem system, uint sessionId, DataPacket netMessage)
    {
        var str = netMessage.Content;
        kcpActor.Logger.Info(str);
        
        kcpActor.SendMessage<RoomChatMessage>(message => { message.Content = str; }, 288, sessionId);
        // gate类内部使用SendMsgToClient回显给客户端
        kcpActor.SendMsgToClient(sessionId, netMessage);
    }
}

public class KcpConnectHandler : ActorController<ActorKcp, ConnectMessage>
{
    protected override void Run(ActorKcp actor, ActorSystem system, MessageInfo info, ConnectMessage data)
    {
        actor.Logger.Info($"session {info.SessionId} connect...");
        actor.SendMessage<RoomEnterMessage>(_ => {}, 288, info.SessionId);
    }
}

public class KcpDisconnectHandler : ActorController<ActorKcp, DisConnectMessage>
{
    protected override void Run(ActorKcp actor, ActorSystem system, MessageInfo info, DisConnectMessage data)
    {
        actor.Logger.Info($"session {info.SessionId} disconnect...");
        actor.SendMessage<RoomLeaveMessage>(_ => {}, 288, info.SessionId);
    }
}